<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <script type="text/javascript" src="../script/config.js"></script>
    <style>
        .swipe {overflow: hidden;position: relative;}
        .swipe-wrap {overflow: hidden; position: relative;}
        .swipe-wrap .swipe-con { float:left; position: relative;}
        .swipe-wrap .swipe-con img{ width:100%; vertical-align: middle;  }
        #main{ padding: 2px; background-color: #e5e5e5;}
        #main .flex-vertical .layout{ background:#e66961 url() right bottom no-repeat; margin: 1.5rem;padding: 1rem; background-size: auto 50%; line-height: 2rem;  color: white; font-size: 1.8rem;border-radius:1rem;height:110px;}
        #main .flex-vertical .layout p{ font-size: 1rem; }
        #main .flex-vertical .layout.ic-hot{ background-color:#f16c3c;font-size: 1.6rem;height:110px;}
        #main .flex-vertical .layout.ic-tag{ background-color: #f3845c;font-size: 1.6rem;height:110px;}
        #main .flex-vertical .layout.ic-like{ background-color:#f3845c;font-size: 1.6rem;height:110px;}
        #main .flex-vertical .layout.ic-lable{background-color: #f16c3c;font-size: 1.6rem;height:110px;}
    .flex-2{ -webkit-box-flex: 2;     -webkit-flex: 2;    flex: 2; }
    .hover{ opacity: .8; }
    .my_card{
      margin:1.5rem;
      margin-top:2rem;
      margin-bottom:2rem;
      /*background-size: auto 50%;*/
    }
    .my_card_a{
       color: white;
      border-radius:1rem;
      font-size: 1.6rem;
      background-color:#f16c3c;
      padding-left:20%;
      height:50px;
    }
    .my_message,.delivery,.qr_code{
            display: flex;
            justify-content: center;
            align-items: center;
            padding-top: 5px;
    }
    .my_message_z,.delivery_z,.qr_code_z,.order_acc{
      padding-top: 10px;
        text-align:center;
        color:white;
    }
</style>
</head>
<body>
  <div id="wrap" class="flex-wrap flex-vertical" >
      <div id="main" class="flex-wrap flex-con" >
           <div class="flex-con flex-wrap flex-vertical">
               <div tapmode="hover" onclick="funOpenArticle( this );" class="flex-wrap flex-con flex-2 layout-wrap">
                   <div class="flex-con layout ic-hot">
                     <div style="display:none;width:50px;height:50px;background-color:red;position:absolute;border-radius:25px;left:8.2rem;top:1.0rem;text-align:center;line-height:50px;" id="tongji2"></div>
                     <div class="qr_code">
                       <img src="../image/my_document.png" style="width:65%;margin:0 auto;"/>
                     </div>
                      <div class="qr_code_z">新的运单</div>
                   </div>
               </div>
               <div tapmode="hover" onclick="funOpenArticle1( this );"  class="flex-wrap flex-con flex-2 layout-wrap">
                   <div class="flex-con layout ic-tag">
                     <div class="delivery">
                       <img src="../image/History_list.png" style="width:60%;"/>
                     </div>
                       <div class="delivery_z">历史单据</div>
                   </div>
               </div>
           </div>
           <div class="flex-wrap flex-con flex-vertical">
               <div tapmode="hover" onclick="funOpenArticle3(this)"  class="flex-wrap flex-con layout-wrap">

                   <div class="flex-con layout ic-like">
                     <div style="width:50px;height:50px;background-color:red;position:absolute;border-radius:25px;right:1.2rem;top:1.0rem;text-align:center;line-height:50px;display:none;" id="tongji"></div>
                     <div class="my_message">
                      <img src="../image/delivery.png" style="width:55%;"/>

                     </div>
                      <div class="order_acc">货物交付</div>
                   </div>
               </div>
               <div class="flex-wrap flex-con">
                  <div tapmode="hover" onclick="message()"  class="flex-wrap flex-con layout-wrap">

                   <div class="flex-con layout ic-lable">

                     <div class="my_message">
                       <div style="width:50px;height:50px;background-color:red;position:absolute;border-radius:25px;text-align:center;line-height:50px;display:none;" id="tongji1"></div>
                      <img src="../image/my_message.png" style="width:55%;"/>
                    </div>
                    <div class="my_message_z">我的合同</div>
                   </div>
                  </div>
               </div>
           </div>
      </div>
      <div class="my_card">
           <div  class="my_card_a" tapmode="hover" onclick="funOpenArticle2(this);">
               <!-- <img src="../image/card.png" style="width:20%;margin:10px auto;float:left;"/> -->
               <img src="../image/card.png" style="width:13%;margin:10px auto;float:left;"/>
               <div style="float:left;line-height:50px;margin-left:5px;" id="mingpian">已检查货物安全</div>
           </div>
      </div>
  </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/swipe.js"></script>
<!-- <script type="text/javascript" src="../script/up_check.js"></script> -->
<script type="text/javascript">
    apiready = function(){
      var top=$api.offset($api.dom('.ic-lable')).t;
      var left=$api.offset($api.dom('.ic-lable')).l;
      var width=$api.offset($api.dom('.ic-lable')).w;
      $api.css($api.dom('#tongji1'),'top:'+(top-10)+'px;left:'+(left+width-45)+'px;');
      api.closeWin({
         name: 'signmain',
         animation:{
           type:"none",
         }
      });
      var user = $api.getStorage('user');
      var lorryid=user.lorryid;
      $api.get(url+'app.php/get_lorry_status?lorry_id='+lorryid,function(ret){
        if(ret.result==0){
          api.openFrame({
              name: 'reject',
              url: '../reject.html',
              bounces:false,
              rect: {
                  x: 0,
                  y: 0,
                  w: api.winWidth,
                  h: api.winHeight
              },
              pageParam: {
                 reason:ret.reject.reason,
                }
           });
        }
      },'json');
      tongji(lorryid);
     setInterval('tongji('+lorryid+')',2000);
     tongji_agreement(lorryid);
    setInterval('tongji_agreement('+lorryid+')',2000);
    tongji_scheduling(lorryid);
    setInterval('tongji_scheduling('+lorryid+')',2000);
    };
    var mySwipe = new Swipe($api.dom('.swipe'), {
        speed: 400,
        auto: 3000,
        continuous: true,
        disableScroll: false,
        stopPropagation: false,
        transitionEnd: function(index, elem) {

        }
    });
    function funOpenArticle( tag ){
//       var user = $api.getStorage('user');
//       var lorryid=user.lorryid;
//       var time=user.time;
//
//     //     var scanner = api.require('scanner');
//     // scanner.open(function(ret, err) {
//         // if (ret.msg) {
//         var FNScanner = api.require('FNScanner');
// FNScanner.openScanner({
//     autorotation: true
// }, function(ret, err) {
//   if(ret.content){
//           $api.append($api.dom('body'), '<audio src="../image/Win.mp3" controls="controls" preload id="music1" hidden>');
//           $api.dom('#music1').play();
//           api.openWin({
//             name: 'scheduling_main',
//             url:  './scheduling_main.html',
//             pageParam: {
//               name:$api.text( $api.dom(".qr_code_z")),
//               scheduling_id:ret.content,
//             }
//           });
//           // var scanner = api.require('scanner');
//           // scanner.closeview();
//             // alert(JSON.stringify(ret.msg));
//             var FNScanner = api.require('FNScanner');
//              FNScanner.closeView();
//         } else {
//           // var scanner = api.require('scanner');
//           // scanner.closeview();
//             // alert(JSON.stringify(err));
//             var FNScanner = api.require('FNScanner');
//               FNScanner.closeView();
//         }
//       });
// check(lorryid,time);

          api.openWin({
            name: 'danju_main',
            url:  './danju_main.html',
            pageParam: {
              name:$api.text( $api.dom(".qr_code_z")),
            }
          });
  }
    function funOpenArticle2(tdg){
      var user = $api.getStorage('user');
      var lorryid=user.lorryid;
      var time=user.time;
      check(lorryid,time);
      upload_map(lorryid);
    // api.openWin({
    //   name: 'mingpian',
    //   url:  './minimain.html',
    //   pageParam: {
    //     name:$api.text( $api.dom("#mingpian")),
    //   }
    // });
  };
  function funOpenArticle1(tdg){
    var user = $api.getStorage('user');
    var lorryid=user.lorryid;
    var time=user.time;

    api.openWin({
        name: 'delivery_z',
        url: './minimain.html',
        pageParam: {
            name: $api.text( $api.dom(".delivery_z")),
       }
    });
    check(lorryid,time);
  }
  function funOpenArticle3(tdg){
    var user = $api.getStorage('user');
    var lorryid=user.lorryid;
    var time=user.time;

    api.openWin({
        name: 'order_acc',
        url: './ordercc_main.html',
        pageParam: {
            name: $api.text( $api.dom(".order_acc")),
       }
    });
    check(lorryid,time);
  }
  function message(){
    var user = $api.getStorage('user');
    var lorryid=user.lorryid;
    var time=user.time;

    api.openWin({
        name: 'my_agreement',
        url: './minimain.html',
        pageParam: {
            name: $api.text( $api.dom(".my_message_z")),
       }
    });
    check(lorryid,time);
  }
  var tongji=function(id){
    $api.get(url+'app.php/tongji?lorry_id='+id,function(ret){
if(ret.result==0){
      if(ret.count==0){
        $api.css($api.dom('#tongji'),'display:none');
      }else{
        $api.css($api.dom('#tongji'),'display:block');
        $api.text($api.dom('#tongji'),ret.count);
      }
    }else{
      $api.css($api.dom('#tongji'),'display:none');
    }
   },'json');
  }

  var tongji_agreement=function(id){
    $api.get(url+'app.php/tongji_agreement?lorry_id='+id,function(ret){
if(ret.result==0){
      if(ret.count==0){
        $api.css($api.dom('#tongji1'),'display:none');
      }else{
        $api.css($api.dom('#tongji1'),'display:block');
        $api.text($api.dom('#tongji1'),ret.count);
      }
    }else{
      $api.css($api.dom('#tongji1'),'display:none');
    }
   },'json');
  }

var tongji_scheduling=function(id){
  $api.get(url+'app.php/wait_schedulings?lorry_id='+id,function(ret){
if(ret.result==0){
    if(ret.schedules.length==0){
      $api.css($api.dom('#tongji2'),'display:none');
    }else{
      $api.css($api.dom('#tongji2'),'display:block');
      $api.text($api.dom('#tongji2'),ret.schedules.length);
    }
  }else{
    $api.css($api.dom('#tongji2'),'display:none');
  }
 },'json');
}

  var upload_map=function(id){
    // alert(1)
    var bMap = api.require('bMap');
    bMap.getLocationServices(function(ret2, err) {
    if (ret2.enable) {
    bMap.getLocation({
        accuracy: '10m',
        autoStop: true,
        filter: 1
    }, function(ret, err) {
        if (ret.status) {
          $api.post(url+'app.php/scmap',{
           body:{
                lorryid:id,
                longitude:ret.lon,
                latitude:ret.lat,
                }
           },function(ret){
          //  alert(ret.desc);
          api.toast({
             msg: '上传地理位置成功',
             duration: 1000,
            location: 'middle'
          });
         },'json');
        } else {
            // alert(err.code);
        }
    });
  } else {
alert("您现在有待交付清单,司机还在运送中,请开启定位");
var mySettingInfo = api.require('mySettingInfo');
mySettingInfo.settingInt({
'index': 2
}, function(ret, err) {
alert(JSON.stringify(ret));
});
}
});
  }
  var check=function(id,time){
    $api.post(url+'app.php/check',{
          body:{lorryid:id,
                time:time,}
         },function(ret){
          if(ret.result==4){
            setTimeout("api.openWin({name:'index',animation:{type:'none',},url:'../index.html'})",500);
             setTimeout("api.closeToWin({name:'index',animation:{type:'none',}})",550);
             setTimeout("api.closeWin({name:'main',animation:{type:'none',}})",600);
            // alert(ret.desc);
            // api.openWin({
            //   name: 'index',
            //   url:  '../index.html',
            // });

             $api.rmStorage('password');
             var key = 'user';
             var user = {};
             var aa=$api.getStorage(key);
             user.lorryid=aa.lorryid;
              user.telephone=aa.telephone;
             user.flag= aa.flag
             user.pass= '';
             $api.setStorage(key, user);
             api.alert({
               title: '提示消息',
               msg: ret.desc,
               buttons: ['确定']
             });
           }else{
            //  alert(ret.desc);
           }
         });
  }
</script>
</html>
